function request(url, method, data) {
  return new Promise((resolve, reject) => {
    const App_url = 'https://api.beebud.cn' + url
    const searchParams = new URLSearchParams()
    if (data) {
      Object?.keys(data).forEach(key => searchParams.append(key, data[key]))
    }
    const config = method === 'post' ? { body: searchParams.toString() } : {}
    const token = window.localStorage.getItem('token') || ''
    fetch(App_url, {
      method: method,
      ...config,
      headers: {
        "Content-Type": 'application/x-www-form-urlencoded',
        "Authorization": token ? `Bearer ${token}` : ''
      }
    })
      .then(response => response.json())
      .then(json => {
        // console.log(json)
        resolve(json)
      })
      .catch(err => console.log('Request Failed', err));
  })
}
function uuid() {
  const temp_url = URL.createObjectURL(new Blob());
  const uuid = temp_url.toString()
  URL.revokeObjectURL(temp_url)
  return uuid.substring(uuid.lastIndexOf('/') + 1)
}
function copyTextToClipboard(text) {
  const textarea = document.createElement('textarea');
  textarea.value = text;
  document.body.appendChild(textarea);
  textarea.select();
  document.execCommand('copy');
  document.body.removeChild(textarea);
  toast('复制成功')
}
function toast(msg, time) {
  const a = `<span class="toast"
style="position:fixed;
  z-index: 9999;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  padding: 5px 16px;
  border-radius: 5px;
  font-size: 14px;
  color: #fff;
  background: rgba(0,0,0, 0.7);"
>${msg}</span>`
  const body = document.querySelector('body')
  const d = document.createElement('div')
  d.style.class = 'toast-container'
  d.innerHTML = a
  body.appendChild(d)
  setTimeout(() => {
    d.remove()
  }, time || 3000)
}
const getQueryVariable = (variable) => {
  const query = window.location.search.substring(1);
  const vars = query.split("&");
  for (let i = 0; i < vars.length; i++) {
    const pair = vars[i].split("=");
    if (pair[0] == variable) { return pair[1]; }
  }
  return (false);
}